package server;

/**
 * Http协议工具类 主要提供响应头信息，我们这里只提供200和404的情况
 *
 * @author zyy
 * @date 2020/12/29 上午7:53
 * @description
 */
public class HttpProtocolUtil {

    /**
     * 为响应码200提供请求头信息
     * @param contentLength
     * @return
     */
    public static String getHttpHeader200(long contentLength) {
        return "HTTP/1.1 200 OK \n" +
                "Content-Type: text/html \n" +
                "Content-Length: " + contentLength + "\n" +
                "\r\n";
    }

    /***
     * 为响应码404提供请求头信息（此处也包含了数据内容）
     * @return
     */
    public static String getHttpHeader404() {
        String str404 = "<h1> 404 NOT FOUNT</h1>";
        return "HTTP/1.1 404 not found \n" +
                "Content-Type: text/html \n" +
                "Content-Length: " + str404.getBytes().length + "\n" +
                "\r\n" + str404;
    }
}
